<?php
class CBlog extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;

	public function __construct()
	{
		$this->_name = R_PRE."blogs";
		$this->_primary = "blog_id";
		parent::__construct();
		
	}

	public function add($data)
	{
		$blogId=$this->insert($data);		
		return $blogId;
	}
	
	public function getList($page, $pageNum)
	{
		$offset = ($page - 1) * $pageNum;
		return $this->fetchAll(null, 'blog_id desc', $pageNum, $offset);
	}
	
	public function getPageCount($pageNum)
	{
		$result = $this->fetchAll();
		return count($result);
	}

	public function edit($itemid,$data)
	{
		$db=$this->getAdapter();
		$where = $db->quoteInto('itemid = ?', $itemid);
		$rows_affected=$db->update($this->_name,$data,$where);
		if ($rows_affected!=1) {
			return false;
		} 
		return true;		
	}
	
	public function delete($itemidArray)
	{		
		$db=$this->getAdapter();
		$itemidString=join(',',$itemidArray);
		$result=$db->query("DELETE FROM $this->_name WHERE itemid IN ($itemidString)");
		return $result;
	}	
}